package com.io;

import java.awt.*;
import java.io.*;

public class Test_4 {
    public static void main(String[] args) throws IOException {
                    copy();
    }
    //复制文件
    public static void copy() throws IOException {
        String pathname="D:\\javacode\\javacode\\J2024_11_17\\gold.png";
        String copy="D:\\javacode\\javacode\\J2024_11_17\\gold2.png";
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(pathname));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(copy));
        int readline=0;
        byte[]buf=new byte[8];
        while((readline=bufferedInputStream.read(buf))!=-1){
            //读: read(byte[] buf),将读到的内容写到buf中去
            bufferedOutputStream.write(buf,0,readline);
            //写:write(byte[] buf,off,len),将buf中从off开始,len个byte写入文件中
        }
        bufferedInputStream.close();
        bufferedOutputStream.close();


    }
}
